<?php

if (isset($config)) {
	if (!checkAdminPrivilege()) {
		redirectUrl("index.php?action=view&page=". $config["special_page_prefix"] . $config["access_error_page"]);
	}
	
	if (isset($_POST["save"])) {
		$page = urldecode($_POST["page"]);
		$text = $_POST["text"];
		savePageContent($page, $text);
		
		redirectUrl("index.php?action=view&page=$page");
	} else if (isset($_POST["cancel"])) {
		$page = $_POST["page"];
	
		redirectUrl("index.php?action=view&page=$page");
	} else if (isset($_GET["page"])) {
		$page = $_GET["page"];
		$encodedPageContent = getEncodedPageContent($page);
		$pageTitle = $page;
		
		include(  $config["theme_dir"] . "/"
				. $config["theme"] . "/"
				. $config["theme_edit"] . ".html" );
	} else {
		redirectUrl("index.php");
	}
} else {
	include("function.php");
}

?>